﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
using System.Drawing;

namespace SPMigrationOracleUtility
{
    class Business
    {
        public object Panel_Prop(Panel pnl)
        {
            int x = 21;
            int y = 40;
            pnl.Location = new Point(x, y);
            return pnl;
        }



        public void _pnl2Trans(DataGridView gvExceldata, Button btnNextPnl2)
        {
            if (gvExceldata.RowCount > 0)
            {
                btnNextPnl2.Enabled = true;
            }
            else
            {
                btnNextPnl2.Enabled = false;
            }
        }

        public void _ExcelData(string excelFileName, ComboBox cboExcelCols, DataGridView gvExceldata)
        {
            try
            {
                FileHelper objHelper = new FileHelper(excelFileName);
                string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;""", excelFileName);
                string query = String.Format("select * from [{0}$]", "Sheet1");
                using (OleDbConnection con = new OleDbConnection(connectionString))
                {
                    con.Open();
                    OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
                    DataTable dt = new DataTable();
                    dataAdapter.Fill(dt);
                    int cnt = dt.Columns.Count;

                    List<ExcelItemPairs> data = new List<ExcelItemPairs>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        cboExcelCols.DisplayMember = "Value";
                        cboExcelCols.Items.Add(new ExcelItemPairs() { Value = Convert.ToString(col.ColumnName), Type = Convert.ToString(col.DataType), SrcName = Convert.ToString(objHelper.FileName) });
                    }

                    DataSet dataSet = new DataSet();
                    dataAdapter.Fill(dataSet);
                    gvExceldata.DataSource = null;
                    gvExceldata.DataSource = dataSet.Tables[0];
                }
            }
            catch (Exception ee)
            {

                MessageBox.Show(ee.Message);
            }
           
        }
    }

}
